<?php

namespace App\Observers\Game\Center;

use App\Caches\Game\UuidWhiteListCache;
use App\Models\Game\Center\UuidWhiteList;

class UuidWhiteListObserver
{
    /**
     * @param UuidWhiteList $data
     */
    public function created(UuidWhiteList $data)
    {
        UuidWhiteListCache::set($data->uuid);
    }

    /**
     * @param UuidWhiteList $data
     */
    public function updated(UuidWhiteList $data)
    {
        //if (!$data->isDirty('uuid')) return;

        // 删除原有, 保存新uuid
        UuidWhiteListCache::del($data->getOriginal('uuid'));
        UuidWhiteListCache::set($data->uuid);
    }

    /**
     * @param UuidWhiteList $data
     */
    public function deleted(UuidWhiteList $data)
    {
        // 设置缓存
        UuidWhiteListCache::del($data->uuid);
    }
}
